# -*- coding: utf-8 -*-
__author__ = 'Administrator'
import logging
import tornado.escape
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.websocket
import httplib2
import urllib
import urlparse
import tornado.autoreload
import allGlobal

#远程请求
class amapViewHandler(tornado.web.RequestHandler):
    def get(self, *args, **kwargs):
        self.render("amap.html", title="amap", WEB_RRESOURCE_DIR=allGlobal.WEB_RRESOURCE_DIR)

class amapDataHandler(tornado.web.RequestHandler):
    http = httplib2.Http(".cache")
    headers = {
        'Content-type': 'application/x-www-form-urlencoded',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36',
        'Accept': 'text/plain'
    }

    def get(self, *args, **kwargs):
        clientversion = self.get_argument("clientversion")
        queryUrl=self.get_argument("queryAddress")
        data = urllib.urlencode({'clientversion': clientversion})
        fullUrl = allGlobal.TUANURL + "/"+ queryUrl + "?" + data
        logging.info(">> "+fullUrl)
        res, content = self.http.request(fullUrl, "GET", None, self.headers)
        self.write(tornado.escape.utf8(content))

    def post(self, *args, **kwargs):
       pass

